const { wyy_request } = require("../../../util/wyy_request");
const APIError = require("../../../middlewares/rest").APIError;


let song = async (ctx) => {

    if (ctx.request.method === 'GET') {
        var mid = ctx.request.query.mid || '347230';
        // var br = ctx.request.query.br || '128';
    } else if (ctx.request.method === 'POST') {
        var mid = ctx.request.body.mid || '347230';
        // var br = ctx.request.body.br || '320';
    }


    // let uin = global.wyy_cookie.uin || '0';


    // let filename = `"${typeMap[br].s}${mid.trim() + mid.trim()}${typeMap[br].e}"`;
    // let mids = `"${mid.trim()}"`;

    // let result = await wyy_request(`https://u.y.wyy.com/cgi-bin/musicu.fcg?format=json&data={"req":{"module":"CDN.SrfCdnDispatchServer","method":"GetCdnDispatch","param":{"guid":"658650575","calltype":0,"userip":""}},"req_0":{"module":"vkey.GetVkeyServer","method":"CgiGetVkey","param":{"filename":[${filename}],"guid":"658650575","songmid":[${mids}],"songtype":[0],"uin":"${uin}","loginflag":1,"platform":"20"}},"comm":{"uin":${uin},"format":"json","ct":24,"cv":0}}`);
    // // console.log(result);
    // // 捕获序列化json出错，防止程序异常退出

    // ctx.rest({
    //     data: {
    //         url: result.data.req_0.data.midurlinfo.length && result.data.req_0.data.midurlinfo[0].purl ? 'https://isure.stream.wyymusic.wyy.com/' + result.data.req_0.data.midurlinfo[0].purl : {}
    //     },
    //     code: "成功"
    // });
    let result = await wyy_request(`https://music.163.com/api/v3/song/detail`, {
        c: '[' + '{"id":' + mid + '}]',
    });
    ctx.rest(result.data);
}

//获取歌曲地址
let song_url = async (ctx) => {

    if (ctx.request.method === 'GET') {
        var mid = ctx.request.query.mid || '33894312';
    } else if (ctx.request.method === 'POST') {
        var mid = ctx.request.body.mid || '33894312';
    }

    let result = await wyy_request(`https://interface3.music.163.com/api/song/enhance/player/url`, {
        ids: '[' + mid + ']',
        br: 999000,
    });
    ctx.rest(result.data);
}

// let songInfo = async (ctx) => {

//     if (ctx.request.method === 'GET') {
//         var rid = ctx.request.query.rid || '156483846';
//     } else if (ctx.request.method === 'POST') {
//         var rid = ctx.request.body.rid || '156483846';
//     }

//     let result = await wyy_request('http://kuwo.cn/api/www/music/musicInfo', {
//         mid: rid.trim(),
//         httpsStatus: 1,
//         reqId: 'e3f36a20-4c05-11eb-b0b7-8b03aa7e4b0d'
//     });

//     ctx.rest(result.data);
// }

module.exports = {
    song,
    song_url
    // songInfo
}